
import pickle

class MatchConfiguration:
	def __init__(self):
		self.plans = []
		self.our_color = 'red'
		self.start_x = 0.0
		self.start_y = 0.0
		self.start_angle = 0.0
	
	def setup(self, world):
		""" setup world according to my start settings, this 
			should be done only at begining of the match
		"""
		world.our_color = self.our_color
		world.start_x = self.start_x 
		world.start_y = self.start_y 
		world.pos_x = self.start_x 
		world.pos_y = self.start_y 
		world.angle = self.start_angle
	
	def copy(self):
		ret = MatchConfiguration()
		ret.plans = self.plans[:]
		ret.our_color = self.our_color
		ret.start_x = self.start_x
		ret.start_y = self.start_y 
		ret.start_angle = self.start_angle 
		return ret

class Database:
	def __init__(self, pickle_name, world):
		""" pickle_name is path to pickled MatchConfiguration object
		"""
		self._configuration = pickle.load( open(pickle_name, 'rb') )
		self._configuration.setup( world )
	
	def pick_plan(self, world):
		""" return plan with top ranking
		"""
		ret = []
		for plan in self._configuration._plans:
			this_rank = plan.calculate_ranking(world)
			element = (this_rank, plan,)
			ret.append( element )
			
		ret.sort( key=lambda x: x[0] )
		return ret









